<template>
	<view class="">
		<view class="tabwrap">
			<view class="tabitem" v-for="(item,index) in tablist" :key="item.name" :class="{active:item.select}"
				@click="clickToggleHandle(item,index)">
				{{item.name}}
			</view>
		</view>
		<view class="mainlist" v-for="item in goodsList" :key="item.id" @click="goMerchantHome(item.id)">
			<image class="images" :src="item.cover" mode="aspectFill"></image>
			<view class="mainright">
				<view class="name">
					{{item.name}}
				</view>
				<view class="detail">
					<view class="wraps">
						距您{{item.distance?item.distance:"999"}}km内 {{item.classify_name}} {{item.address}}
					</view>
				</view>
				<view class="rate">
					<!-- <u-rate readonly size="20" v-model="item.evaluate_rate" active-color="#FFC300"></u-rate> -->
					<view class="">
						<image class="rateimg" v-for="item1 in item.attach.seller_level.level_data.image_data"  :src="item1" mode="aspectFill"></image>
					</view>
					<text class="c6 f24" v-if="item.sales_volume!=0">已售{{item.sales_volume}}单</text>
				</view>
				<view class=" flex_dq" v-if="item.is_marketing">
					<image class="manzeng" :src="baseUrl+ '/static/image/manz2.png'" mode="aspectFill"></image>
				</view>
				<view class="itemss" v-if="item.goods.length>0" v-for="item1 in  item.goods  " :key="item1.id">
					<view class="wrapleft">
						<view class="tag">团</view>
						<text class="price">￥{{item1.price}}</text>
						<text class="content"> {{item1.name}}</text>
					</view>
					<view class="jifen">
						+{{item1.integral_proportion}}%more值
					</view>
				</view>
				<view class="itemss" v-if="item.goods.length==0 &&item.quick_pay=='1'">
					<view class="wrapleft">
						<view class="tag2">快</view>
						<text class="price">快捷买单</text>
					</view>
					<view class="jifen">
						+{{item.quick_integral_proportion}}%more值
					</view>
				</view>
				<view class="itemss" v-if="item.goods.length==0 &&item.quick_pay=='0'">
					<view class="wrapleft">
						<view class="tag3">到</view>
						<text class="price">到店消费</text>
					</view>
		
				</view>
			</view>
		</view>
		<noDatas :xxxList="goodsList" :status="status"></noDatas>
		<view class="empty3"></view>
	</view>
</template>

<script>
	import {
		geocoder
	} from "../../api/other.js"
	import {
		recommendSeller
	} from '../../api/local.js';
	export default {
		data() {
			return {
				page:1,
				size:10,
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				latitude: "",
				longitude: "",
				types: "",
				goodsList: [],
				tablist: [{
						name: "距离优先",
						value: 2,
						select: false
					},
					{
						name: "信誉优先",
						value: 5,
						select: false
					},
					{
						name: "销量优先",
						value: 3,
						select: false
					}
				],
			}
		},
		onLoad() {
			if (uni.getStorageSync("longitude")) {
				this.latitude = uni.getStorageSync("latitude")
				this.longitude = uni.getStorageSync("longitude")
				this.getlist()
			} else {
				// 获取定位
				this.sss()
			}
		},
		methods: {
			clickToggleHandle(ele) {
				this.types = ele.value
				this.tablist.forEach(item => {
					if (item.name == ele.name) {
						item.select = true
					} else {
						item.select = false
					}
				})
				this.page = 1
				this.getlist()
			},
			sss() {
				let that = this;
				uni.getLocation({
					success: function(res) {
						uni.setStorageSync("latitude", res.latitude)
						uni.setStorageSync("longitude", res.longitude)
						that.latitude = res.latitude
						that.longitude = res.longitude
						that.page = 1
						that.getlist()
						let data = {
							lat: res.latitude,
							lng: res.longitude,
						};
						geocoder(data).then(res => {
							console.log('逆解析', res)
							if (res.code == 1) {
								uni.setStorageSync('cityName', that.cityName)
								uni.setStorageSync('addressInfo', res.data)
							}
						})
					},
					fail: function(res) {
						that.latitude = "39.90"
						that.longitude = "116.41"
						that.cityName = "全国"
						uni.setStorageSync("latitude", that.latitude)
						uni.setStorageSync("longitude", that.longitude)
						// this.obtainAddress()
						that.page = 1
						that.getlist()
						// console.log(res, "杀杀杀杀杀杀杀杀杀")
					}
				})
			},
			getlist(){
				uni.showLoading({
					title: '加载中',
				});
				let data = {
					page: this.page,
					page_size: this.size,
					latitude: this.latitude,
					longitude: this.longitude,
					sort_type: this.types,
					is_wisdom:1
				};
				recommendSeller(data).then(res => {
					uni.hideLoading()
					console.log('商品列表', res)
					let list = res.data.data;
					this.goodsList = this.page == 1 ? list : this.goodsList.concat(list);
					console.log(this.goodsList, '商品上哦');
					if (list.length < this.size) this.status = 'nomore';
					else this.status = 'loading';
				})
			},
			goMerchantHome(id) {
				console.log(11111, id);
				uni.navigateTo({
					url: '/pagesMy/groundCat/merchantHomepagew?id=' + id
				})
			},
			
		},
		onReachBottom() {
			console.log('触底加载');
			if (this.status != 'nomore') {
				this.page = this.page + 1
				this.getlist()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabwrap {
		width: 690rpx;
		margin: 0 auto;
		margin-top: 30rpx;
		display: flex;
		align-items: center;
		position: relative;
		z-index: 100;
		justify-content: space-between;
		padding: 0 30rpx;

		.tabitem {
			width: 156rpx;
			height: 52rpx;
			background: #fff;
			border-radius: 102rpx 102rpx 102rpx 102rpx;
			text-align: center;
			font-weight: 400;
			font-size: 24rpx;
			color: #666666;
			line-height: 52rpx;
		}
	}

	.active {
		background: #ffc300 !important;
	}
	.mainlist {
		width: 690rpx;
		min-height: 230rpx;
		background: #FFFFFF;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		display: flex;
		padding-bottom: 30rpx;
	
		.images {
			margin-top: 20rpx;
			margin-left: 14rpx;
			width: 190rpx;
			height: 190rpx;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
		}
	
		.mainright {
			width: 460rpx;
			margin-top: 20rpx;
			margin-left: 20rpx;
	
			.name {
				width: 420rpx;
				font-weight: 500;
				font-size: 30rpx;
				color: #3D3D3D;
				white-space: nowrap;
				/* 防止文本换行 */
				overflow: hidden;
				/* 隐藏溢出内容 */
				text-overflow: ellipsis;
				/* 显示省略号 */
	
			}
	
			.detail {
				display: flex;
				justify-content: space-between;
				margin-top: 10rpx;
	
				.wraps {
					width: 420rpx;
					font-family: Source Han Sans, Source Han Sans;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					white-space: nowrap;
					/* 防止文本换行 */
					overflow: hidden;
					/* 隐藏溢出内容 */
					text-overflow: ellipsis;
				}
	
				>text {
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
				}
			}
	
			.itemss {
				// width: 420rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 22rpx;
	
				.wrapleft {
					display: flex;
					align-items: center;
	
					width: 320rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #333333;
	
					.tag {
						width: 28rpx;
						height: 28rpx;
						background: rgba(253, 48, 63, 0.6);
						border-radius: 4rpx 4rpx 4rpx 4rpx;
						text-align: center;
						line-height: 28rpx;
						font-weight: 400;
						font-size: 22rpx;
						color: #FFFFFF;
					}
	
					.tag2 {
						width: 28rpx;
						height: 28rpx;
						background: #60CAFE;
						border-radius: 4rpx 4rpx 4rpx 4rpx;
						text-align: center;
						line-height: 28rpx;
						font-weight: 400;
						font-size: 22rpx;
						color: #FFFFFF;
					}
	
					.tag3 {
						width: 28rpx;
						height: 28rpx;
						background: #FC6414;
						border-radius: 4rpx 4rpx 4rpx 4rpx;
						text-align: center;
						line-height: 28rpx;
						font-weight: 400;
						font-size: 22rpx;
						color: #FFFFFF;
					}
	
					.price {
						font-weight: 500;
						font-size: 24rpx;
						color: #E78C4C;
						margin-left: 8rpx;
					}
	
					.content {
						width: 180rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #333333;
						margin-left: 10rpx;
						white-space: nowrap;
						/* 防止文本换行 */
						overflow: hidden;
						/* 隐藏溢出内容 */
						text-overflow: ellipsis;
					}
				}
	
				.jifen {
					// width: 140rpx;
					height: 32rpx;
					background: linear-gradient(270deg, #FA2222 2%, #FFC400 98%);
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					text-align: center;
					line-height: 32rpx;
					font-weight: 500;
					font-size: 20rpx;
					color: #FFFFFF;
				}
			}
		}
	}
	.manzeng {
		width: 280rpx;
		height: 36rpx;
		margin-top: 12rpx;
	}
	.rateimg{
			width: 30rpx;
			height: 30rpx;
			margin: 6rpx;
		}
</style>